package com.marquee.friends;


import java.util.ArrayList;
import java.util.Collection;

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.facebook.FacebookException;
import com.facebook.FacebookOperationCanceledException;
import com.facebook.Session;
import com.facebook.model.GraphUser;
import com.facebook.widget.WebDialog;
import com.facebook.widget.WebDialog.OnCompleteListener;
import com.marquee.R;
import com.marquee.R.drawable;
import com.marquee.R.id;
import com.marquee.R.layout;
import com.marquee.customview.MyFragment;

public class Frag_Friends_My extends MyFragment {

	 

	View view;
	
	
	
	
	ListView listView_friends;
	
	private String LOG_TAG = "test";
	
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
    	view = (LinearLayout) inflater.inflate(R.layout.friends_fragment_my, container, false);
    	
    	listView_friends = (ListView)view.findViewById(R.id.listView_friends);
    	
    	//listview, arraylist, adapter 초기화
    	ListView lstActionList = (ListView)view.findViewById(R.id.listView_friends);
    	ArrayList<Person> arrPersonList = new ArrayList<Person>();
    	AddListViewAdapter adptActionList = new AddListViewAdapter(getActivity().getApplicationContext(), R.layout.friends_my_list_item, arrPersonList);

    	//adapter 세팅
    	lstActionList.setAdapter(adptActionList);

    	//list의 내용을 채울 ArrayList 작성

    	Resources res = this.getResources();
    	Person mPerson;
    	
    	
    	for(int i=0; i<3; i++){
    	mPerson = new Person();
    	mPerson.setProfile(res.getDrawable(R.drawable.thm_general_default_profile_image));
    	mPerson.setName("이태진");
    	mPerson.setMessage("안녕하세요 이태진입니다");
    	arrPersonList.add(mPerson);

    	mPerson = new Person();
    	mPerson.setProfile(res.getDrawable(R.drawable.thm_general_default_profile_image));
    	mPerson.setName("김민구");
    	mPerson.setMessage("안녕하세요 김민구입니다");
    	arrPersonList.add(mPerson);

    	mPerson = new Person();
    	mPerson.setProfile(res.getDrawable(R.drawable.thm_general_default_profile_image));
    	mPerson.setName("박상권");
    	mPerson.setMessage("몇글자까지 써지는지 테스트 해보려고합니다 어떻게될까요");
    	arrPersonList.add(mPerson);
    	
    	mPerson = new Person();
    	mPerson.setProfile(res.getDrawable(R.drawable.thm_general_default_profile_image));
    	mPerson.setName("박강순");
    	mPerson.setMessage("이름이 길경우는?");
    	arrPersonList.add(mPerson);
    	}
    	
    	
    	//listview refresh(?)
    	adptActionList.notifyDataSetChanged();
    	
    	
    	
    	
    	return view;		
    
    }
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
		
    	
      
	}
	
	public class Person {

		 private Drawable profile;
		 private String name;
		 private String message;
		 
		 public Drawable getProfile() {
		  return profile;
		 }
		 public void setProfile(Drawable icon) {
		  this.profile = icon;
		 }
		 public String getName() {
		  return name;
		 }
		 public void setName(String name) {
		  this.name = name;
		 }
		 public String getMessage() {
			  return message;
			 }
			 public void setMessage(String message) {
			  this.message = message;
			 }
		}
	
	class AddListViewAdapter extends ArrayAdapter<Person>{
		 private Context context;
		 private int layout;
		 private ArrayList<Person> personList;
		 private LayoutInflater layoutInflater;
		 
		 
		 public AddListViewAdapter(Context context, int textViewResourceId, ArrayList<Person> objects) {
		  super(context, textViewResourceId, objects);
		  // TODO Auto-generated constructor stub
		  this.context = context;
		  this.layout = textViewResourceId;
		  this.personList = objects;
		                //LayoutInflater 생성
		  this.layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		 }
		 
		 @Override
		 public View getView(int position, View convertView, ViewGroup parent) {
		  // TODO Auto-generated method stub
			 Person mPerson = personList.get(position);

		  if(convertView == null){
		                        //xml 파일로 정의된 layout 을 View 클래스로 변환
		   convertView = layoutInflater.inflate(layout, null);
		  }

		  if(mPerson != null){
		                        //convertView 라는 View 오브젝트를 이용해서 각각의 콤포넌트를 컨트롤
			  ImageView imgProfile = (ImageView) convertView.findViewById(R.id.profile);
		   TextView tvName = (TextView) convertView.findViewById(R.id.name);
		   TextView tvMessage = (TextView) convertView.findViewById(R.id.message);
		   
		   imgProfile.setImageDrawable(mPerson.getProfile());
		   tvName.setText(mPerson.getName());
		   tvMessage.setText(mPerson.getMessage());
		  
		  }

		  return convertView;
		 }
		}
	
    
  
   
    
    
}

